package tests;


import java.util.GregorianCalendar;


import tester.TestMethod;
import tester.Example;
import tester.Tester;
import tester.utilities.TesterUtility;
import tests.pojos.Address;
import tests.pojos.AuthorCirc;
import tests.pojos.AuthorWithArrays;
import tests.pojos.BookCirc;
import tests.pojos.BookWithArrays;
import tests.pojos.Person;

@Example
public class CloneTests {
	
	public void cloneFailureTestsCommonObject(Tester t) {

		Address add = new Address(203, "Boston ave", "Medford", 43023,
				"OH");
		Address addClone = TesterUtility.objectCopy(add);
		add.setCity("Granville");
		t.checkExpect(add, addClone);

		Person p = new Person("Wes", 23, new Address(203, "Boston Ave",
				"Medford", 02155, "MA"));
		Person pClone = TesterUtility.objectCopy(p);
		p.setAddress(new Address());
		t.checkExpect(p, pClone);		

		/* Test circularly ref. data */
		BookWithArrays book = new BookWithArrays("Foo", 1965);
		BookWithArrays book1 = new BookWithArrays("Bar", 1970);
		AuthorWithArrays wes = new AuthorWithArrays("Wes");
		wes.addBook(book);
		wes.addBook(book1);
		book.setAuthor(wes);
		book1.setAuthor(wes);

		BookWithArrays bookClone = TesterUtility.objectCopy(book);
		book.setAuthor(new AuthorWithArrays());
		AuthorWithArrays wesClone = TesterUtility.objectCopy(wes);
		wes.setName("feeee");
		t.checkExpect(book, bookClone);
		t.checkExpect(wes, wesClone);

		AuthorCirc authorCirc = new AuthorCirc("Wes");
		BookCirc bookCirc = new BookCirc("Foo", 1965);
		authorCirc.setBook(bookCirc);
		bookCirc.setAuthor(authorCirc);

		AuthorCirc authorCircClone = TesterUtility.objectCopy(authorCirc);
		authorCirc.setBook(new BookCirc("figger", 32));
		BookCirc bookCircClone = TesterUtility.objectCopy(bookCirc);
		bookCirc.setAuthor(new AuthorCirc("Boo"));
		t.checkExpect(authorCirc, authorCircClone);
		t.checkExpect(bookCirc, bookCircClone);

		Comparable<Integer> compInt = new Integer(5);
		Comparable<Integer> compIntClone = TesterUtility.objectCopy(compInt);
		compInt = new Integer(7);
		t.checkExpect(compInt, compIntClone);	
	}

	@TestMethod
	public void testCommonObjectCloneSuccess(Tester t) {
		
		Address add = new Address(203, "Boston ave", "Medford", 43023,
				"OH");
		Address addClone = TesterUtility.objectCopy(add);
		t.checkExpect(add, addClone);

		Person p = new Person("Wes", 23, new Address(203, "Boston Ave",
				"Medford", 02155, "MA"));
		Person pClone = TesterUtility.objectCopy(p);
		t.checkExpect(p, pClone);
		
		/* Test circularly ref. data */
		BookWithArrays book = new BookWithArrays("Foo", 1965);
		BookWithArrays book1 = new BookWithArrays("Bar", 1970);
		AuthorWithArrays wes = new AuthorWithArrays("Wes");
		wes.addBook(book);
		wes.addBook(book1);
		book.setAuthor(wes);
		book1.setAuthor(wes);

		BookWithArrays bookClone = TesterUtility.objectCopy(book);
		AuthorWithArrays wesClone = TesterUtility.objectCopy(wes);
		t.checkExpect(book, bookClone);
		t.checkExpect(wes, wesClone);

		AuthorCirc authorCirc = new AuthorCirc("Wes");
		BookCirc bookCirc = new BookCirc("Foo", 1965);
		authorCirc.setBook(bookCirc);
		bookCirc.setAuthor(authorCirc);

		AuthorCirc authorCircClone = TesterUtility.objectCopy(authorCirc);
		BookCirc bookCircClone = TesterUtility.objectCopy(bookCirc);
		t.checkExpect(authorCirc, authorCircClone);
		t.checkExpect(bookCirc, bookCircClone);

		Comparable<Integer> compInt = new Integer(5);
		Comparable<Integer> compIntClone = TesterUtility.objectCopy(compInt);
		t.checkExpect(compInt, compIntClone);		
		
		java.util.GregorianCalendar calendarFail = new GregorianCalendar(2008,
				12, 23);
		java.util.GregorianCalendar calendarCloneFail = 
			TesterUtility.objectCopy(calendarFail);
		t.checkExpect(calendarFail, calendarCloneFail);
			
	}
}
